ABC143 D - Triangles
提出
TLE
code: python
import itertools
n = int(input())
l = list(map(int, input().split()))
ans = 0
for sticks in itertools.combinations(l, 3):
if (sticks0 < sticks1 + sticks2 and sticks1 < sticks0 + sticks2 and sticks2 < sticks0 + sticks1): ans += 1
print(ans)
解答
code: python
from bisect import bisect_left
n = int(input())
l = sorted(list(map(int, input().split())))
# a, b を固定
# c < a + b
ans = 0
for a in range(n): # a: la for b in range(a + 1, n): # b: lb ans += bisect_left(l, la + lb) - (b + 1) # c が取れる範囲(c のインデックス - b+1) print(ans)
テーマ
メモ
aが最大辺のとき三角形の成立条件は b+c < a
TLE
code: python
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
max_side = max(side1, max(side2, side3))
if (max_side < (side1 + side2 + side3) - max_side):
ans += 1
print(ans)
提出
code: python
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
restl = []
for i in range(n-1, 0, -1):
# 最小の組み合わせだがそれ以外は条件を満たすとは限らない
print(l)
print(restl)
提出
TLE
code: python
import itertools
n = int(input())
l = list(map(int, input().split()))
# ans = 0
# for a, b, c in itertools.combinations(l, 3):
# if a < b+c and b < c+a and c < a+b:
# ans += 1
# print(ans)
l.sort(reverse=True)